<!-- 编辑 基本信息 -->
<template>
	<view class="pb50">
		<uni-card spacing="0" margin="0" :is-shadow="false" :border="false">
			<uni-forms ref="formRef" :model="formData" :rules="formRules" :label-width="150" label-position="top">
				<uni-forms-item label="联系电话" name="phonenumber" required>
					<uni-easyinput v-model="formData.phonenumber" placeholder="请输入联系电话" trim />
				</uni-forms-item>
			</uni-forms>
		</uni-card>
	</view>
	<view class="sticky-b0 p10">
		<button @click="submit" type="default" class="basicbutton m10" hover-class="basicbutton-hover">确定修改</button>
	</view>
</template>

<script lang="ts" setup>
	import { getUser, setUser } from "@/utils/storage"
	import { informationEdit } from "@/api/user"
	import { ref } from 'vue'
	let userData = getUser()
	const formData = ref({
		phonenumber: '',
	})
	const formRules = ref({
		phonenumber: {
			rules: [{
				required: true,
				errorMessage: '请输入联系电话'
			}, {
				pattern: /^[1][3,4,5,7,8][0-9]{9}$/,
				errorMessage: '联系电话格式错误'
			}]
		}
	})
	let formRef = ref(null)


	function submit() {
		formRef.value.validate().then(res => {
			informationEdit({				...userData,
				...formData.value			}).then(res => {
				if (res.code == '200') {
					let user  = { ...userData, ...formData.value}
					setUser(user)
					uni.navigateBack({
						delta: 1
					})
				}
			})
		}).catch(err => {
			uni.showToast({ icon: "none", title: err[0].errorMessage })
		})
	}
</script>

<style lang="scss" scoped>

</style>